package com.hulizuofang.wol.chat.client.ui.event.receive;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HasHandlers;
import com.hulizuofang.wol.chat.client.data.ChatUser;

public class ReceiveChatEvent extends GwtEvent<ReceiveChatHandler> {
	private static final Type<ReceiveChatHandler> TYPE = new Type<ReceiveChatHandler>();
	private final ChatUser sender;
	private final String message;

	ReceiveChatEvent(ChatUser sender, String message) {
		this.sender = sender;
		this.message = message;
	}
	
	public ChatUser getSender() {
		return sender;
	}
	
	public String getMessage() {
		return message;
	}

	public static void fire(final HasHandlers source, ChatUser sender, String message) {
		source.fireEvent(new ReceiveChatEvent(sender, message));
	}

	public static Type<ReceiveChatHandler> getType() {
		return TYPE;
	}
	@Override
	public Type<ReceiveChatHandler> getAssociatedType() {
		return getType();
	}

	@Override
	protected void dispatch(ReceiveChatHandler handler) {
		handler.onReceive(this);
	}

}
